<template>
  <!--我的关注页  -->
  <div class="comment">
    <myheader page="我的关注">
      <span
        slot="left"
        class="iconfont iconjiantou2"
        @click="$router.back()"
      ></span>
    </myheader>
    <div class="focus">
      <div class="list" v-for="(item, index) in filt" :key="item.id">
        <div class="box">
          <img :src="item.head_img" alt="" />
          <div class="center">
            <p>{{ item.nickname }}</p>
            <span>{{ item.create_date | istime_filter("-") }}</span>
          </div>
          <span @click="cancel(item.id, index)">取消关注</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import myheader from "@/components/header.vue";
import axios from "@/utils/myaxios.js";
import { myuser_follows, user_unfollow } from "@/apis/post.js";
import { istime_filter } from "@/utils/time_filter.js";
export default {
  data() {
    return {
      // 文本输入框是否聚焦
      filt: [],
    };
  },
  components: {
    myheader,
  },
  filters: {
    istime_filter,
  },
  async mounted() {
    let res = await myuser_follows();
    this.filt = res.data.data;
    this.filt = this.filt.map((v) => {
      v.head_img = axios.defaults.baseURL + v.head_img;
      return v;
    });
  },
  methods: {
    async cancel(id, index) {
      let res = await user_unfollow(id);
      console.log(res);
      this.$toast.success(res.data.message);
      this.filt.splice(index, 1);
    },
  },
};
</script>


<style lang='less' scoped>
.list {
  .box {
    display: flex;
    padding: 25px 10px;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ccc;
    img {
      display: block;
      width: 50/360 * 100vw;
      height: 50/360 * 100vw;
      border-radius: 50%;
      padding: 0 10px;
    }
    .center {
      flex: 1;
      > p {
        line-height: 30px;
        font-size: 14px;
      }
      > span {
        font-size: 12px;
        color: #999;
      }
    }
    span {
      height: 30px;
      background-color: #eee;
      font-size: 13px;
      border-radius: 30px;
      line-height: 30px;
      padding: 0px 15px;
    }
  }
}
</style>
